<?php
namespace Common\Util;
class AttachmentUtil{
    /**
     * 添加附件
     * @param $file_info
     * @return mixed
     */
    public static function createAttachment($file_info){
        return M('attachment')->add($file_info);
    }

    /**
     * 获取附件信息
     * @param string $md5
     * @return bool|mixed
     */
    public static function getAttachmentInfoByMd5($md5 = ''){
        if(empty($md5)) return false;
        $info = M('attachment')->where(['md5'=>$md5])->find();
        return $info?$info:false;
    }

    /**
     * 获取附件列表
     * @param array $where
     * @param string $order
     * @param int $pagesize
     * @param int $pagenum
     * @return array
     */
    public static function getAccachmentList($where = [],$order = '',$pagesize = 1,$pagenum = 10){
        $t_attachment = M("attachment");
        $startnum = ($pagesize - 1)*$pagenum;
        $where = $where;
        if(empty($order)) $order = 'id Desc';
        $data_list = $t_attachment
            ->where($where)
            ->order($order)
            ->page($startnum, $pagenum)
            ->select();
        return $data_list?$data_list:[];
    }
}